<script type="text/javascript">
	
	function findTotalHumenRecords()
	{
		<?php foreach($employees as $e => $employee) { ?>
				var total = 0;
				<?php foreach($branches as $b => $branch) { ?>
					if($('#HumanResourceValue_<?php echo $branch["Branch"]["id"]."_".$employee["Employee"]["id"] ?>').val().replace(",", "") != '')
						total += parseInt($('#HumanResourceValue_<?php echo $branch["Branch"]["id"]."_".$employee["Employee"]["id"] ?>').val().replace(",", ""));
				<?php } ?>
				$('#humen_total_<?php echo $employee["Employee"]["id"] ?>').html($.formatNumber(total, {format:"#,###"}));
		<?php } ?>
	}

	jQuery(document).ready(function($) {
		findTotalHumenRecords();

		
		$("#human_record_frame input").blur(function(){
			findTotalHumenRecords();
		});		
	});

</script>

<div class="humanResources form" id="human_record_frame">
	
	
	<div style="margin-bottom:20px;">
    
    <form action="<?php echo $this->Html->url(array('action' => 'add')); ?>" method="POST" id="filter_add">
    
    <h4><?php __('Tỉnh/Thành'); ?>:
        <select onchange="document.getElementById('HumanResourceCityId').value = this.value;document.getElementById('filter_add').submit()" name="filter_city_id">
            <?php foreach($cities as $c ) {
                $selected = "";
                if($c["id"] == $city["id"])
                {
                    $selected = 'selected="selected"';
                }
            ?>
                <option value="<?php echo $c["id"] ?>" <?php echo $selected; ?> ><?php echo $c["name"] ?></option>
            <?php } ?>
        </select>
    </h4>
    <h4><?php __('Năm'); ?>:
        <select onchange="document.getElementById('HumanResourceYear').value = this.value;document.getElementById('filter_add').submit()" name="filter_year">        
            <?php for($i=1991; $i < 2031; $i++ ) {
                $selected = "";
                if($year == $i)
                {
                    $selected = 'selected="selected"';
                }
            ?>
                <option value="<?php echo $i ?>" <?php echo $selected; ?> ><?php echo $i ?></option>
            <?php } ?>
        </select>
    </h4>
    <h4><?php __('Quý'); ?>:
        <select onchange="document.getElementById('HumanResourceQuarter').value = this.value;document.getElementById('filter_add').submit()" name="filter_quarter">        
            <?php for($i=1; $i < 5; $i++ ) {
                $selected = "";
                if($quarter == $i)
                {
                    $selected = 'selected="selected"';
                }
            ?>
                <option value="<?php echo $i ?>" <?php echo $selected; ?> ><?php echo $i ?></option>
            <?php } ?>
        </select>
    </h4>
    </form>
    
</div>
	
<?php echo $this->Form->create('HumanResource');?>
	<fieldset>
		<legend><?php __('Cập nhật thông tin nhân lực'); ?></legend>
	<?php
		echo $this->Form->input('year', array('label'=>'Năm', 'type'=>'hidden', 'value'=>$year));
		echo $this->Form->input('quarter', array('label'=>'Quý', 'type'=>'hidden', 'value'=>$quarter));
		echo $this->Form->input('city_id', array('label'=>'Tỉnh/Thành', 'type'=>'hidden', 'value'=>$city["id"]));
		echo $this->Form->input('unit_id', array('label'=>'Đơn vị', 'empty'=> true));
	?>	
	
	<div class="input text required">
		<label for="HumanResourceValue">Bảng cập nhật</label>		
		<table cellpadding="0" cellpadding="0" id="input_table">
			<tr>
				<th></th>
				<?php foreach($employees as $key => $employee) { ?>
					<th><?php echo $employee["Employee"]["name"] ?></th>
				<?php } ?>
			</tr>
			<?php foreach($branches as $b => $branch) { ?>
				<tr>
					<td><?php echo $branch["Branch"]["name"] ?></td>
					<?php foreach($employees as $e => $employee) { ?>
						<td>
							<input class="iit" type="text" id="HumanResourceValue_<?php echo $branch["Branch"]["id"]."_".$employee["Employee"]["id"] ?>" value="<?php if($values[$branch["Branch"]["id"]][$employee["Employee"]["id"]] != "") echo number_format($values[$branch["Branch"]["id"]][$employee["Employee"]["id"]],0,".", ",") ?>" maxlength="255" name="data[values][<?php echo $branch["Branch"]["id"] ?>][<?php echo $employee["Employee"]["id"] ?>]" />
						</td>
					<?php } ?>
				</tr>
			<?php } ?>
			<tr>
				<td>Tổng cộng</td>
				<?php foreach($employees as $e => $employee) { ?>
					<td style="text-align: right" id="humen_total_<?php echo $employee["Employee"]["id"] ?>">
					</td>
				<?php } ?>
			</tr>
		</table>
	</div>
	</fieldset>
<?php echo $this->Form->end(__('Lưu thông tin', true));?>
</div>



<div class="actions">
	<h3><?php __('Chức năng'); ?></h3>
	<ul>		
		<li><?php echo $this->Html->link(__('Danh sách đơn vị RHM', true), array('controller' => 'branches', 'action' => 'index')); ?> </li>
		<li><?php echo $this->Html->link(__('Thêm đơn vị RHM', true), array('controller' => 'branches', 'action' => 'add')); ?> </li>		
	</ul>
</div>